package com.ruoyi.local.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.local.domain.LayerList;
import com.ruoyi.local.service.ILayerListService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.domain.Ztree;

/**
 * 图层管理Controller
 * 
 * @author ruoyi
 * @date 2020-12-23
 */
@Controller
@RequestMapping("/local/layerlist")
public class LayerListController extends BaseController
{
    private String prefix = "local/layerlist";

    @Autowired
    private ILayerListService layerListService;

    @RequiresPermissions("local:layerlist:view")
    @GetMapping()
    public String layerlist()
    {
        return prefix + "/layerlist";
    }



    /**
     * 查询图层管理树列表
     */
    @RequiresPermissions("local:layerlist:list")
    @PostMapping("/list")
    @ResponseBody
    public List<LayerList> list(LayerList layerList)
    {
        List<LayerList> list = layerListService.selectLayerListList(layerList);
        return list;
    }

    /**
     * 导出图层管理列表
     */
    @RequiresPermissions("local:layerlist:export")
    @Log(title = "图层管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LayerList layerList)
    {
        List<LayerList> list = layerListService.selectLayerListList(layerList);
        ExcelUtil<LayerList> util = new ExcelUtil<LayerList>(LayerList.class);
        return util.exportExcel(list, "layerlist");
    }

    /**
     * 新增图层管理
     */
    @GetMapping(value = { "/add/{layerId}", "/add/" })
    public String add(@PathVariable(value = "layerId", required = false) Long layerId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(layerId))
        {
            mmap.put("layerList", layerListService.selectLayerListById(layerId));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存图层管理
     */
    @RequiresPermissions("local:layerlist:add")
    @Log(title = "图层管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LayerList layerList)
    {
        return toAjax(layerListService.insertLayerList(layerList));
    }

    /**
     * 修改图层管理
     */
    @GetMapping("/edit/{layerId}")
    public String edit(@PathVariable("layerId") Long layerId, ModelMap mmap)
    {
        LayerList layerList = layerListService.selectLayerListById(layerId);
        mmap.put("layerList", layerList);
        return prefix + "/edit";
    }

    /**
     * 修改保存图层管理
     */
    @RequiresPermissions("local:layerlist:edit")
    @Log(title = "图层管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LayerList layerList)
    {
        return toAjax(layerListService.updateLayerList(layerList));
    }

    /**
     * 删除
     */
    @RequiresPermissions("local:layerlist:remove")
    @Log(title = "图层管理", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{layerId}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("layerId") Long layerId)
    {
        return toAjax(layerListService.deleteLayerListById(layerId));
    }

    /**
     * 选择图层管理树
     */
    @GetMapping(value = { "/selectLayerlistTree/{layerId}", "/selectLayerlistTree/" })
    public String selectLayerlistTree(@PathVariable(value = "layerId", required = false) Long layerId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(layerId))
        {
            mmap.put("layerList", layerListService.selectLayerListById(layerId));
        }
        return prefix + "/tree";
    }

    /**
     * 加载图层管理树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = layerListService.selectLayerListTree();
        return ztrees;
    }
}
